<!DOCTYPE HTML>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <META HTTP-EQUIV="Pragma" CONTENT="no-cache">
    <META HTTP-EQUIV="Cache-Control" CONTENT="no-cache">
    <META HTTP-EQUIV="Expires" CONTENT="0">
    <META http-equiv="X-UA-Compatible" content="IE=edge">
    <title>TVI项目管理平台</title>
    <link rel="stylesheet" type="text/css" href="../libs/bootstrap-3.3.0/css/bootstrap.min.css"/>
	<link rel="stylesheet" type="text/css" href="../assets/css/dpl-min.css" />
    <link rel="stylesheet" type="text/css" href="../assets/css/bui-min.css" />
    <link rel="stylesheet" type="text/css" href="../assets/css/main-min.css" />
    <style>
        .bui-pop-menu{
            z-index: 1;
        }
        .dl-log-user{
            margin-right: 10px;
        }
        .hidden{
            display: none;
        }
        * {
            -webkit-box-sizing: content-box;
            -moz-box-sizing: content-box;
            box-sizing: content-box;
        }
    </style>
</head>
<body>
    <div class="header">
        <div class="dl-title">
            <h1>TVI项目管理平台</h1>
            <!--<img src="../assets/img/top.png">-->
        </div>
        <div class="dl-log" id="link"><span class="dl-log-user">欢迎您，root</span><span class="x-caret x-caret-down" style="border-top: 4px solid #ffffff;"></span><!--<a href="javascript:void(0)" id="logoff" title="退出系统" class="dl-log-quit">[退出]</a>-->
        </div>
    </div>

    <div class="content">
        <div class="dl-main-nav">
            <div class="dl-inform"><div class="dl-inform-title"><s class="dl-inform-icon dl-up"></s></div></div>
            <ul id="J_Nav"  class="nav-list ks-clear">
            </ul>
        </div>
        <ul id="J_NavContent" class="dl-tab-conten">

        </ul>
    </div>
    <div style="position: fixed;
    top: 0;
    width: 100%;
    height: 1080px;
    z-index: 40;
    opacity: .5;
    background-color: black;display: none;" class="modalDom">
    </div>
    <div class="modalDom" style="z-index: 101;display: none;">
        <iframe src="" style="position: fixed;
    top: 14%;
    left: 34.5%;
    width: 500px;
    height: 391px;
    z-index: 45;" id="modalIframe">

        </iframe>
    </div>
    <script type="text/javascript" src="../assets/js/jquery-1.8.1.min.js"></script>
    <script type="text/javascript" src="../assets/js/bui-min.js"></script>
    <script type="text/javascript" src="../assets/js/common/main-min.js"></script>
    <script type="text/javascript" src="../assets/js/config-min.js"></script>
    <script type="text/javascript" src="../js/common.js"></script>

    <script type="text/javascript">
        $(function () {
            BUI.use('bui/menu',function(Menu){

                var dropMenu = new Menu.PopMenu({
                    trigger : '#link',
                    autoRender : true,
                    triggerEvent : 'mouseenter',
                    triggerHideEvent : 'mouseleave',
                    autoHideType:'leave',
                    width : 85,
                    children : [{
                        id:'modifyPassword',
                        content : "修改密码"
                    },{
                        id:'userInfo',
                        content : "个人资料"
                    },{
                        id:'logoff',
                        content : "退出登录"
                    }]
                });
                dropMenu.on('itemclick', function(){
                    if(dropMenu.getSelectedValue()=='logoff'){
                        window.sessionStorage.clear();
                        $.ajax({type: "GET",url: ctx + "/user/logout"});
                        window.location.href = ctx;
                    }else if(dropMenu.getSelectedValue()=='modifyPassword'){
                        $('#modalIframe').attr('src','Public/modal.html?type=pwd');
                        //$('.modalDom').show();
                    }
                    else if(dropMenu.getSelectedValue()=='userInfo'){
                        $('#loginCode').val(window.sessionStorage.getItem('managerUser'));
                        $('#modalIframe').attr('src','Public/modal.html?type=user');
                        //$('.modalDom').show();
                    }
                });
            });


            var user = window.sessionStorage.getItem('managerUser');

            if(user === null){
                window.location.href = "login.html";
            } else{
                $(".dl-log-user").html('欢迎您，'+user)
                $.ajax({
                        type: "POST",
                        url: ctx + "/menu/queryFunctionMenu",
                        traditional:true,
                        data:{
                            loginCode:user
                    },
                    success: function(data){
                        if(data.data.length == 0){
                            alert('logincode:'+user+',返回空数据')
                            var bln=confirm("是否退出系统？")
                            if (bln==true){
                                window.location.href = "login.html";
                            }
                        }else{
                            setDom(data.data)
                            BUI.use('common/main', function () {
                                var config =  setMenu(data.data);
                                new PageUtil.MainPage({
                                    modulesConfig: config
                                });
                            });
                            //获取角色权限列表
                            getUserRoleFuncCode();
                        }
                    }
                })
            }
            frameHeight = $(document).height()-96;
            });
        function setMenu(obj) {
            var menuData = [];
            for(var i =0;i<obj.length;i++){
                var parentObj = {};
                parentObj.menu = [];
                parentObj.id = obj[i].id;
                parentObj.homePage = obj[i].homePage;
                var selfObj = {};
                selfObj.items = [];
                selfObj.text = obj[i].menu[0].text;
                parentObj.menu.push(selfObj);
                for(var j=0;j<obj[i].menu[0].items.length;j++){
                    var sonObj = {};
                    sonObj.id = obj[i].menu[0].items[j].menuUrl;
                    sonObj.text = obj[i].menu[0].items[j].menuName;
                    sonObj.href = obj[i].menu[0].items[j].menuUrl;
                    selfObj.items.push(sonObj)
                }
                menuData.push(parentObj)
            }
            return menuData
        }
        function setDom(obj){
            var html = '';
            for(var i =0;i<obj.length;i++){
                html +='<li class="nav-item"><div class="nav-item-inner nav-order">'+ obj[i].menu[0].text +'</div></li>'
            }
            $("#J_Nav").append(html);
            $(".nav-item").eq(0).click()
        }

            function getUserRoleFuncCode() {
                $.ajax({
                    type:"GET",
                        url:ctx+"/user/getRoleFuncCodeByUser",
                    success: function(data){
                        if(data.data.length != 0){
                            window.sessionStorage.setItem("roleFuncCode",JSON.stringify(data.data));
                        }
                    }

                });
            }


    </script>

</body>
</html>